Passed
Push — master ( 506943...0f9777 )
by Plamen
01:27
created

TableSingleton.constructor   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 29
Bugs 0 Features 2
Metric Value
cc 1
eloc 35
c 29
b 0
f 2
nc 1
nop 0
dl 0
loc 50
rs 9.0399
1
//https://addyosmani.com/resources/essentialjsdesignpatterns/book/#singletonpatternjavascript
2
var TableSingleton = (function(){
3
    // Instance stores a reference to the Singleton
4
    var instance;
5
    function initInstance(){
6
        // Singleton
7
        // Private methods and variables
8
9
        this.static = {};
10
        for(var method in window.table_methods){
11
            this.static[method] = window.table_methods[method];
12
        }
13
        this.static['strAsc'] = String.fromCharCode(9650);
14
        this.static['strDesc'] = String.fromCharCode(9660);
15
        var ColumnHover=this.static.ColumnHover;
16
        var Export =    this.static.Export.bind(this.static);
17
        var Filter =    this.static.Filter.Run.bind(this.static);
18
        var Init =      this.static.Init.Run.bind(this.static);
19
        var GoPage =    this.static.GoPage.Run.bind(this.static);
20
        var ReloadData= this.static.ReloadData.bind(this.static);
21
        var Sort =      this.static.Sort.bind(this.static);
22
        return {
23
            rq: null,
24
            ColumnHover: ColumnHover,//table_method.ColumnHover
25
            Export: Export,
26
            Filter: Filter,
27
            GoPage: GoPage,
28
            init: Init,
29
            LoadEndCalback: function(){}, /*Allows override: function(tableId){if(tableId){...}}*/
30
            ReloadData: ReloadData,
31
            Sort: Sort
32
        };
33
    }
34
    return {
35
        //Get the Singleton instance if one exists, or create one if it doesn't
36
        getInstance: function(){
37
            if(!instance){
38
                instance = initInstance();
39
            }
40
            return instance;
41
        }
42
    };
43
})();
44
var table = TableSingleton.getInstance();
45